<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/9/16
 * Time: 15:25
 * 私人订制首页套餐
 */

namespace app\api\controller;


use think\Db;

class Privatesetmeal extends Base
{
    public $user_id;
    public $create_time;
    public $page;
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id, $time, $value, $reqKey);
        if($auth == 112){
            echo json_encode(['status' => 301, 'msg' => $this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }
    
    /**
     * 轮播
     * @return \think\response\Json
     */
    public function privateBanner(){
        $banner = Db::table('up_private_banner')->where('pb_status', 1)->field('pb_image, pb_ps_id')->order('pb_time desc')->select();
        if($banner){
            return json(['status' => 200, 'msg' => $banner]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 套餐列表
     * @return \think\response\Json
     */
    public function setmealList(){
        $stock = Db::table('up_private_stock')->where('stock_user_id', $this->user_id)->field('stock_ps_id, stock_number')->buildSql();
        $list = Db::table('up_private_setmeal')
            ->join([$stock => 'a'], 'a.stock_ps_id = ps_id', 'LEFT')
            ->where('ps_status', 1)
            ->field('ps_id, ps_name, ps_image, ps_price, ps_vip_price, ps_spec, ps_xg, IFNULL(a.stock_number, 0) stockNumber')
            ->order('ps_time desc')
            ->select();
        if($list){
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 套餐详情
     * @return \think\response\Json
     * ps_id        套餐ID
     */
    public function setmealDetail(){
        $ps_id = input('ps_id');
        $detail = Db::table('up_private_setmeal')
            ->where('ps_id', $ps_id)
            ->field('ps_id, ps_name, ps_images, ps_content, ps_time, ps_price, ps_vip_price, ps_spec, 
            ps_xg, ps_db_img, ps_detail_img, ps_pf_img, ps_mj_img, ps_image')
            ->find();
        if($detail['ps_images']){
            $detail['ps_images'] = explode(',', $detail['ps_images']);
        }else{
            $detail['ps_images'] = [];
        }
        return json(['status' => 200, 'msg' => $detail]);
    }

    /**
     * 私人订制承诺图
     * @return \think\response\Json
     */
    public function userAgreement(){
        $content = Db::table('up_about')->where('id', 12)->value('content');
        return json(['status' => 200, 'msg' => $content]);
    }
}